package com.hs.srm.admin.modules.pricemanagement.service.impl;

import java.util.List;
import java.util.Map;

import cn.hutool.system.SystemUtil;

import com.hs.srm.admin.modules.vendor.entity.VendorInfoEntity;
import com.hs.srm.admin.modules.vendor.service.VendorService;
import com.hs.srm.base.modules.sys.entity.SysUserEntity;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.pricemanagement.dao.InquiryQuotationDao;
import com.hs.srm.admin.modules.pricemanagement.dao.ParityDao;
import com.hs.srm.admin.modules.pricemanagement.entity.InquiryQuotationEntity;
import com.hs.srm.admin.modules.pricemanagement.service.InquiryQuotationService;
import com.hs.srm.base.common.annotation.DataFilter;
import com.hs.srm.base.common.utils.Constant;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;


@Service("inquiryQuotationService")
public class InquiryQuotationServiceImpl extends ServiceImpl<InquiryQuotationDao, InquiryQuotationEntity> implements InquiryQuotationService {
    @Autowired
    private VendorService vendorService;

    @Override
    public String selectversion() {

        return this.baseMapper.selectversion();
    }

    @Override
    public String selectnum() {

        return this.baseMapper.selectnum();
    }

    @Override
    public InquiryQuotationEntity selectByNameInquiryTotalCode(String params) {
        return this.baseMapper.selectByNameInquiryTotalCode(params);
    }

    @Autowired
    private ParityDao parityDao;

    /**
     * 分页查询
     */
    @Override
    @DataFilter
    public PageUtils queryPage(Map<String, Object> params) {
        // 从列表页面获取对应的值
        String purchRequestCode = (String) params.get("purchRequestCode");//采购申请单号
        Page<InquiryQuotationEntity> page = this.selectPage(
                new QueryParam<InquiryQuotationEntity>(params).getPage(),
                new EntityWrapper<InquiryQuotationEntity>()
                        .like(StringUtils.isNotBlank(purchRequestCode), "purch_request_code", purchRequestCode)
                        .addFilterIfNeed(!ObjectUtils.isEmpty(params.get(Constant.SQL_FILTER)),
                                (String) params.get(Constant.SQL_FILTER)));
        return new PageUtils(page);
    }

    @Override
    public InquiryQuotationEntity findbyId(String id) {

        return this.baseMapper.findbyId(id);
    }

   /* @Override
    public PageUtils selectDetailPage(Map<String, Object> params) {
        // 从列表页面获取对应的值
        String vendorCode = (String) params.get("vendorCode");//采购申请单号
        String factory = (String) params.get("factory");//工厂
        //标识
        String username = (String) params.get("username");
        Page<InquiryQuotationEntity> page = this.selectDetailPage(
                new QueryParam<InquiryQuotationEntity>(params).getPage(),
                new EntityWrapper<InquiryQuotationEntity>()
                        .like(StringUtils.isNotBlank(vendorCode), "vendor_code", vendorCode)
                        .like(StringUtils.isNotBlank(factory), "factory", factory)
                        .eq(StringUtils.isNotBlank(username),"vendor_code",username)
                        .addFilterIfNeed(!ObjectUtils.isEmpty(params.get(Constant.SQL_FILTER)),
                                (String) params.get(Constant.SQL_FILTER)), params
        );
        return new PageUtils(page);
    }*/

    @Override
    public PageUtils selectDetailPage(Map<String, Object> params) {
        Page<InquiryQuotationEntity> page = this.selectDetailPage(
                new QueryParam<InquiryQuotationEntity>(params).getPage(), new EntityWrapper<InquiryQuotationEntity>(),
                params);
        return new PageUtils(page);
    }

    private Page<InquiryQuotationEntity> selectDetailPage(Page<InquiryQuotationEntity> page,
                                                          Wrapper<InquiryQuotationEntity> wrapper,
                                                          Map<String, Object> params) {
        page.setRecords(this.baseMapper.selectDetailPage(page, wrapper, params));
        return page;
    }

    @Override
    public List<InquiryQuotationEntity> findByNpkID(String npkId) {
        return this.baseMapper.findByNpkID(npkId);
    }

    @Override
    public List<InquiryQuotationEntity> findbyInquiryQuotation() {

        return this.baseMapper.findbyInquiryQuotation();
    }

    @Override
    public List<InquiryQuotationEntity> findbyIds(List<String> id) {

        return this.baseMapper.findbyIds(id);
    }


    @Override
    public List<InquiryQuotationEntity> findByOaDocId(String OaDocId) {
        return this.baseMapper.findByOaDocId(OaDocId);
    }

    //查询供应商税码
    @Override
    public String getVendorTaxCode(String vendorCode) {
        return this.baseMapper.getVendorTaxCode(vendorCode);
    }



}